import Nerv from "nervjs";
import Taro, { request as _request } from "@tarojs/taro-h5";
import { View, Button } from "@tarojs/components";

class Axios extends Taro.Component {
  render() {
    const [list, setList] = Taro.useState(Array());
    const getAxios = () => {
      _request({
        url: 'https://apiblog.jspang.com/default/getArticleList'
      }).then(res => {
        console.log('res: ', res);
      });
    };
    const getAxios2 = async () => {
      const res2 = await _request({
        url: 'https://apiblog.jspang.com/default/getArticleList'
      });
      console.log('res2: ', res2.data.list);
      setList(res2.data.list);
    };
    return <View>
            第三个页面:获取axios请求
            <View>
                <Button onClick={getAxios}>
                    获取异步数据
                </Button>
                <Button onClick={getAxios2}>
                    获取异步数据2
                </Button>
               {list.map((v, i) => {
          return <View key={i}>
                    {v.title}
                       </View>;
        })}
            </View>
        </View>;
  }

  componentDidMount() {
    super.componentDidMount && super.componentDidMount();
  }

  componentDidShow() {
    super.componentDidShow && super.componentDidShow();
  }

  componentDidHide() {
    super.componentDidHide && super.componentDidHide();
  }

}

export default Axios;